import click
from frappe.commands import pass_context
from frappe.gettext.translate import compile_translations


@click.command("trans")
@click.option("--app", help="指定要编译翻译的应用", default="laoyu_en")
@pass_context
def trans(context, app="laoyu_en"):
    try:
        compile_translations(target_app=app, locale="zh", force=True)
        click.secho(f"✅ 应用 {app} 的翻译编译完成", fg="green")
    except Exception as e:
        click.secho(f"❌ 翻译编译失败: {str(e)}", fg="red")
